<?php
require dirname(__FILE__) . DIRECTORY_SEPARATOR . 'autoload.php';

use payClass\Datebase;
use payClass\QRcode;
use payClass\pay\Config;

/**
 * 出款
 */
class Payment
{
	public static function paymentDo()
	{
		$db     = new Datebase();

		$config = new Config();

		$param  = $db->param();

		// 数据检测
		$verifyRes = $db->verifyDraw($param);

		if ($verifyRes != 1) exit($verifyRes);

		$data = [
			'mchid'        => Config::$merchant,
			'out_trade_no' => $param['order'],
			'money'        => sprintf("%.2f", $param['amount']),
			'bankname'     => $param['bank_Code'],
			'ifsc'         => $param['ifsc'],
			'accountname'  => $param['account_Name'],
			'cardnumber'   => $param['account_Number'],
			'mobile'       => $param['phone'],
			'email'        => $param['email'],
			'notify_url'   => Config::$paymentNotifyUrl,
		];
		$data['pay_md5sign'] = Config::getSignMsg($data);

		$curlRes = Config::setHttpRequest(Config::$api . 'Payment_Dfpay_add.html', $data);
//print_r($curlRes);die;
		$resArray = json_decode($curlRes, true);

		if ($resArray['status'] != 'success') $db->ajaxReturn(['code'=>2,'msg'=>$resArray['msg']]);

		$db->ajaxReturn(['code'=>1,'msg'=>'提交成功']);
	}
}

Payment::paymentDo();
